package StringT;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: Administrator
 * \* Date: 2021/11/18
 * \* Time: 20:45
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
class Money implements Cloneable{
    public double m=12.5;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Person implements Cloneable{
    public int age;
    public Money money=new Money();
    public void eat(){
        System.out.println("吃！");
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
       // return super.clone();
        Person tmp=(Person) super.clone();
        tmp.money=(Money) this.money.clone();
        return money;
    }
}
public class TestDemo {

    public static void main(String[] args)throws CloneNotSupportedException {
        Person person1=new Person();
        Person person2= (Person) person1.clone();
        System.out.println(person1.money.m);
        System.out.println(person2.money.m);
        System.out.println("=============================");
        person2.money.m=99.9;
        System.out.println(person1.money.m);
        System.out.println(person2.money.m);
    }

    public static void main1(String[] args) throws CloneNotSupportedException {
        Person person1=new Person();
        person1.age=99;
        Person person2= (Person) person1.clone();
        System.out.println(person2);

        System.out.println("=============================");
        person2.age=199;
        System.out.println(person1);
        System.out.println(person2);
    }

}
